#include "mystdio.h"
#include <string.h>
#include <unistd.h>
#define MYFILE "log.txt"

int main()
{
  MY_file *fp = my_fopen(MYFILE, "w");
  if (fp == NULL)
    return 1;

  const char *str = "hello my fwrite";
  int ret = 2000;
  while (ret)
  {
    char buffer[1024];
    snprintf(buffer, sizeof(buffer), "%s:%d ", str, ret--);

    size_t size = my_fwrite(buffer, strlen(buffer), 1, fp);
    sleep(1);

    printf("写入:%lu个字节\n", size);

    if (ret % 5 == 0)
      my_fwrite("\n", strlen("\n"), 1, fp);
  }
  my_fclose(fp);

  return 0;
}
